package com.lulin.mall.product.thread;

import java.util.concurrent.*;

/**
 * ComplatableFuture异步编排介绍
 *
 * @author lulin
 * @date 2022/12/1 10:34
 */
public class ComplatableFutureDome2 {
    //创建1个线程池对象
    private static ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5, 50, 10,
            TimeUnit.SECONDS,
            new LinkedBlockingDeque<>(100),
            Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.AbortPolicy()
    );

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> supplyAsync = CompletableFuture.supplyAsync(() -> {
            System.out.println("supplyAsync——线程开始了。。。");
            int i = 100 / 50;
            System.out.println("supplyAsync——线程结束了。。。");
            return i;
        }, poolExecutor).handle((res, exex) -> {
            System.out.println("res = " + res);
            System.out.println("exex = " + exex);
            return res * 2;
        });
        System.out.println("获取线程的返回结果：" + supplyAsync.get());
    }


}
